unit Amy.Chromium.Core;

interface

uses System.SysUtils, System.Classes, Winapi.Windows, Winapi.Messages, Vcl.Controls
  , System.Generics.Collections, System.Generics.Defaults, System.Rtti
  , ceflib, cefvcl, Log4D
  , Amy.Chromium
  ;

type

  TAmyChromiumWebContainer = class;

  TCefWebMianfest = class
  end;


  /// <summary>
  /// Cef Web Core
  /// </summary>
  TAmyChromium = class(TInterfacedObject, IAmyChromium)
  strict private
    class var
      FInstance: TAmyChromium;
  private
    FWebContainers: TDictionary<THandle, TAmyChromiumWebContainer>;
    FExtensions: TDictionary<string, TValue>;

    procedure AddWebContainer(Context: TAmyChromiumWebContainer);
    procedure RemoveWebContainer(Context: TAmyChromiumWebContainer);
  public
    {IAmyChromium}
    procedure RegisterExtension(name: string; value: TValue);
    function CreateWebContainer(Parent: TWinControl): IAmyChromiumWebContainer;
  public
    constructor Create; virtual;
    destructor Destroy; override;

    property Extensions: TDictionary<string, TValue> read FExtensions;
  public
    class function GetInstance: TAmyChromium;
  end;

  /// <summary>
  /// Web Context for CefBrowser Instance
  /// </summary>
  TAmyChromiumWebContainer = class(TInterfacedObject, IAmyChromiumWebContainer)
  private
    FAmyChromium: TAmyChromium;
    FParent: TWinControl;
    FWebBrowser: TChromium;
    FDebugger: Boolean;
    FURL: string;
  private
    procedure SetURL(const URL: string);
    function GetURL: string;
    procedure SetDebugger(const Value: Boolean);
    function GetDebugger: Boolean;
  protected
    /// <summary>
    /// Create Chromium instance
    /// </summary>
    procedure CreateWebContainer;
    {$REGION 'Chromium Events CallBack'}
    procedure DoChromiumProcessMessageReceived(Sender: TObject; const browser: ICefBrowser;
      sourceProcess: TCefProcessId; const message: ICefProcessMessage; out Result: Boolean);
    procedure DoChromiumAddressChange(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const url: ustring);
    procedure DoChromiumAfterCreated(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumBeforeBrowse(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const request: ICefRequest; isRedirect: Boolean; out Result: Boolean);
    procedure DoChromiumBeforeClose(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumBeforeContextMenu(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const params: ICefContextMenuParams; const model: ICefMenuModel);
    procedure DoChromiumBeforeDownload(Sender: TObject; const browser: ICefBrowser; const downloadItem: ICefDownloadItem;
      const suggestedName: ustring; const callback: ICefBeforeDownloadCallback);
    procedure DoChromiumBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
      targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
      var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient;
      var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
    procedure DoChromiumBeforeResourceLoad(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const request: ICefRequest; const callback: ICefRequestCallback; out Result: TCefReturnValue);
    procedure DoChromiumBeforeUnloadDialog(Sender: TObject; const browser: ICefBrowser; const messageText: ustring;
      isReload: Boolean; const callback: ICefJsDialogCallback; out Result: Boolean);
    procedure DoChromiumCancelGeolocationPermission(Sender: TObject; const browser: ICefBrowser;
      const requestingUrl: ustring; requestId: Integer);
    procedure DoChromiumCertificateError(Sender: TObject; const browser: ICefBrowser; certError: Integer;
      const requestUrl: ustring; const sslInfo: ICefSslInfo; const callback: ICefRequestCallback; out Result: Boolean);
    procedure DoChromiumClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
    procedure DoChromiumConsoleMessage(Sender: TObject; const browser: ICefBrowser; const message, source: ustring;
      line: Integer; out Result: Boolean);
    procedure DoChromiumContextMenuCommand(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags; out Result: Boolean);
    procedure DoChromiumContextMenuDismissed(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame);
    procedure DoChromiumDialogClosed(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumDownloadUpdated(Sender: TObject; const browser: ICefBrowser;
      const downloadItem: ICefDownloadItem; const callback: ICefDownloadItemCallback);
    procedure DoChromiumDragEnter(Sender: TObject; const browser: ICefBrowser; const dragData: ICefDragData;
      mask: TCefDragOperations; out Result: Boolean);
    procedure DoChromiumDraggableRegionsChanged(Sender: TObject; const browser: ICefBrowser; regionsCount: NativeUInt;
      regions: PCefDraggableRegionArray);
    procedure DoChromiumFavIconUrlChange(Sender: TObject; const browser: ICefBrowser; const iconUrls: TStrings);
    procedure DoChromiumFileDialog(Sender: TObject; const browser: ICefBrowser; mode: TCefFileDialogMode; const title,
      defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer;
      const callback: ICefFileDialogCallback; out Result: Boolean);
    procedure DoChromiumFindResult(Sender: TObject; const browser: ICefBrowser; identifier, count: Integer;
      const selectionRect: PCefRect; activeMatchOrdinal: Integer; finalUpdate: Boolean);
    procedure DoChromiumFullScreenModeChange(Sender: TObject; const browser: ICefBrowser; fullscreen: Boolean);
    procedure DoChromiumGetAuthCredentials(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring;
      const callback: ICefAuthCallback; out Result: Boolean);
    procedure DoChromiumGetResourceHandler(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const request: ICefRequest; out Result: ICefResourceHandler);
    procedure DoChromiumGotFocus(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumJsdialog(Sender: TObject; const browser: ICefBrowser; const originUrl, acceptLang: ustring;
      dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring; callback: ICefJsDialogCallback;
      out suppressMessage, Result: Boolean);
    procedure DoChromiumKeyEvent(Sender: TObject; const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: PMsg;
    out Result: Boolean);
    procedure DoChromiumLoadEnd(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      httpStatusCode: Integer);
    procedure DoChromiumLoadError(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      errorCode: Integer; const errorText, failedUrl: ustring);
    procedure DoChromiumLoadingStateChange(Sender: TObject; const browser: ICefBrowser; isLoading, canGoBack,
      canGoForward: Boolean);
    procedure DoChromiumLoadStart(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame);
    procedure DoChromiumOpenUrlFromTab(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
      out Result: Boolean);
    procedure DoChromiumPluginCrashed(Sender: TObject; const browser: ICefBrowser; const pluginPath: ustring);
    procedure DoChromiumPreKeyEvent(Sender: TObject; const browser: ICefBrowser; const event: PCefKeyEvent;
      osEvent: PMsg; out isKeyboardShortcut, Result: Boolean);
    procedure DoChromiumProtocolExecution(Sender: TObject; const browser: ICefBrowser; const url: ustring;
      out allowOsExecution: Boolean);
    procedure DoChromiumQuotaRequest(Sender: TObject; const browser: ICefBrowser; const originUrl: ustring;
      newSize: Int64; const callback: ICefRequestCallback; out Result: Boolean);
    procedure DoChromiumRenderProcessTerminated(Sender: TObject; const browser: ICefBrowser;
      status: TCefTerminationStatus);
    procedure DoChromiumRenderViewReady(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumRequestGeolocationPermission(Sender: TObject; const browser: ICefBrowser;
      const requestingUrl: ustring; requestId: Integer; const callback: ICefGeolocationCallback; out Result: Boolean);
    procedure DoChromiumResetDialogState(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumResourceRedirect(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const request: ICefRequest; var newUrl: ustring);
    procedure DoChromiumResourceResponse(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
    const request: ICefRequest; const response: ICefResponse; out Result: Boolean);
    procedure DoChromiumRunModal(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
    procedure DoChromiumSetFocus(Sender: TObject; const browser: ICefBrowser; source: TCefFocusSource;
      out Result: Boolean);
    procedure DoChromiumStatusMessage(Sender: TObject; const browser: ICefBrowser; const value: ustring);
    procedure DoChromiumTakeFocus(Sender: TObject; const browser: ICefBrowser; next: Boolean);
    procedure DoChromiumTitleChange(Sender: TObject; const browser: ICefBrowser; const title: ustring);
    procedure DoChromiumTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean);
    {$ENDREGION}
  protected
    {IAmyChromiumWebContainer}
    function GetAmyChromium: IAmyChromium;
  public
    constructor Create(aParent: TWinControl); virtual;
    destructor Destroy; override;

    property URL: string read GetURL write SetURL;
  end;

var
  Logger: TLogLogger;

implementation

{ TAmyChromium }

procedure TAmyChromium.AddWebContainer(Context: TAmyChromiumWebContainer);
begin
  FWebContainers.Add(Context.FParent.Handle, Context);
end;

constructor TAmyChromium.Create;
begin
  FWebContainers := TDictionary<THandle, TAmyChromiumWebContainer>.Create();
  FExtensions := TDictionary<string, TValue>.Create;
end;

function TAmyChromium.CreateWebContainer(Parent: TWinControl): IAmyChromiumWebContainer;
var
  WebContainer: TAmyChromiumWebContainer;
begin
  WebContainer := TAmyChromiumWebContainer.Create(Parent);
  WebContainer.FAmyChromium := Self;
  WebContainer.CreateWebContainer;
  Result := WebContainer;
end;

destructor TAmyChromium.Destroy;
begin
  FExtensions.Free;
  FWebContainers.Free;
  inherited;
end;

class function TAmyChromium.GetInstance: TAmyChromium;
begin
  if FInstance = nil then
  begin
    Logger.Debug('TAmyChromium.GetInstance');
    FInstance := TAmyChromium.Create;
  end;
  Result := FInstance;
end;

procedure TAmyChromium.RegisterExtension(name: string; value: TValue);
begin
  FExtensions.Add(name, value);
end;

procedure TAmyChromium.RemoveWebContainer(Context: TAmyChromiumWebContainer);
begin
  if FWebContainers.ContainsKey(Context.FParent.Handle) then
    FWebContainers.Remove(Context.FParent.Handle);
end;

{ TAmyChromiumWebContainer }

constructor TAmyChromiumWebContainer.Create(aParent: TWinControl);
begin
  FParent := aParent;
  FWebBrowser := nil;
  FURL := '';
  FDebugger := False;
end;

procedure TAmyChromiumWebContainer.CreateWebContainer;
  procedure InitWebContainer;
  begin
    {$REGION 'Chromium Event CallBack Binding'}
    FWebBrowser.OnProcessMessageReceived := DoChromiumProcessMessageReceived;
    FWebBrowser.OnLoadStart              := DoChromiumLoadStart;
    FWebBrowser.OnLoadEnd                := DoChromiumLoadEnd;
    FWebBrowser.OnLoadError              := DoChromiumLoadError;

    FWebBrowser.OnTakeFocus              := DoChromiumTakeFocus;
    FWebBrowser.OnSetFocus               := DoChromiumSetFocus;
    FWebBrowser.OnGotFocus               := DoChromiumGotFocus;
    FWebBrowser.OnBeforeContextMenu      := DoChromiumBeforeContextMenu;
    FWebBrowser.OnContextMenuCommand     := DoChromiumContextMenuCommand;
    FWebBrowser.OnContextMenuDismissed   := DoChromiumContextMenuDismissed;
    FWebBrowser.OnPreKeyEvent            := DoChromiumPreKeyEvent;
    FWebBrowser.OnKeyEvent               := DoChromiumKeyEvent;
    FWebBrowser.OnLoadingStateChange     := DoChromiumLoadingStateChange;

    FWebBrowser.OnAddressChange          := DoChromiumAddressChange;
    FWebBrowser.OnTitleChange            := DoChromiumTitleChange;
    FWebBrowser.OnFavIconUrlChange       := DoChromiumFavIconUrlChange;
    FWebBrowser.OnFullScreenModeChange   := DoChromiumFullScreenModeChange;
    FWebBrowser.OnTooltip                := DoChromiumTooltip;
    FWebBrowser.OnStatusMessage          := DoChromiumStatusMessage;
    FWebBrowser.OnConsoleMessage         := DoChromiumConsoleMessage;
    FWebBrowser.OnBeforeDownload         := DoChromiumBeforeDownload;
    FWebBrowser.OnDownloadUpdated        := DoChromiumDownloadUpdated;

    FWebBrowser.OnRequestGeolocationPermission := DoChromiumRequestGeolocationPermission;
    FWebBrowser.OnCancelGeolocationPermission  := DoChromiumCancelGeolocationPermission;
    FWebBrowser.OnJsdialog                     := DoChromiumJsdialog;

    FWebBrowser.OnBeforeUnloadDialog           := DoChromiumBeforeUnloadDialog;
    FWebBrowser.OnResetDialogState             := DoChromiumResetDialogState;
    FWebBrowser.OnDialogClosed                 := DoChromiumDialogClosed;
    FWebBrowser.OnBeforePopup                  := DoChromiumBeforePopup;
    FWebBrowser.OnAfterCreated                 := DoChromiumAfterCreated;
    FWebBrowser.OnBeforeClose                  := DoChromiumBeforeClose;
    FWebBrowser.OnRunModal                     := DoChromiumRunModal;
    FWebBrowser.OnClose                        := DoChromiumClose;

    FWebBrowser.OnBeforeBrowse                 := DoChromiumBeforeBrowse;
    FWebBrowser.OnOpenUrlFromTab               := DoChromiumOpenUrlFromTab;
    FWebBrowser.OnBeforeResourceLoad           := DoChromiumBeforeResourceLoad;
    FWebBrowser.OnGetResourceHandler           := DoChromiumGetResourceHandler;
    FWebBrowser.OnResourceRedirect             := DoChromiumResourceRedirect;
    FWebBrowser.OnResourceResponse             := DoChromiumResourceResponse;
    FWebBrowser.OnGetAuthCredentials           := DoChromiumGetAuthCredentials;
    FWebBrowser.OnQuotaRequest                 := DoChromiumQuotaRequest;
    FWebBrowser.OnProtocolExecution            := DoChromiumProtocolExecution;
    FWebBrowser.OnCertificateError             := DoChromiumCertificateError;
    FWebBrowser.OnPluginCrashed                := DoChromiumPluginCrashed;
    FWebBrowser.OnRenderViewReady              := DoChromiumRenderViewReady;
    FWebBrowser.OnRenderProcessTerminated      := DoChromiumRenderProcessTerminated;

    FWebBrowser.OnFileDialog                   := DoChromiumFileDialog;
    FWebBrowser.OnDragEnter                    := DoChromiumDragEnter;
    FWebBrowser.OnDraggableRegionsChanged      := DoChromiumDraggableRegionsChanged;

    FWebBrowser.OnFindResult                   := DoChromiumFindResult;
    {$ENDREGION}
  end;
begin
  if FWebBrowser <> nil then
    Exit;
  FWebBrowser := TChromium.Create(FParent);
  FWebBrowser.Parent := FParent;
  FWebBrowser.Align := alClient;
  FWebBrowser.Show;
  InitWebContainer;
  FAmyChromium.AddWebContainer(Self);
end;

destructor TAmyChromiumWebContainer.Destroy;
begin
  FAmyChromium.RemoveWebContainer(Self);
  FAmyChromium := nil;
  FParent := nil;
  if Assigned(FWebBrowser) then
  begin
    FWebBrowser.ParentWindow := 0;
    FreeAndNil(FWebBrowser);
  end;
  inherited;
end;

{$REGION ' Chromium Event CallBack implementation '}

procedure TAmyChromiumWebContainer.DoChromiumAddressChange(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const url: ustring);
begin

end;

procedure TAmyChromiumWebContainer.DoChromiumAfterCreated(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug('Chromium.DoChromiumAfterCreated');
end;

procedure TAmyChromiumWebContainer.DoChromiumBeforeBrowse(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest; isRedirect: Boolean; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumBeforeBrowse: ' + request.Url);
end;

procedure TAmyChromiumWebContainer.DoChromiumBeforeClose(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug('Chromium.DoChromiumBeforeClose');
end;

procedure TAmyChromiumWebContainer.DoChromiumBeforeContextMenu(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
  Logger.Debug('Chromium.DoChromiumBeforeContextMenu');
end;

procedure TAmyChromiumWebContainer.DoChromiumBeforeDownload(Sender: TObject; const browser: ICefBrowser;
  const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback);
begin
  Logger.Debug('Chromium.DoChromiumBeforeDownload');
end;

procedure TAmyChromiumWebContainer.DoChromiumBeforePopup(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
  userGesture: Boolean; var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient;
  var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumBeforePopup');
end;

procedure TAmyChromiumWebContainer.DoChromiumBeforeResourceLoad(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest; const callback: ICefRequestCallback; out Result: TCefReturnValue);
begin
  Logger.Debug('Chromium.DoChromiumBeforeResourceLoad: ' + request.Url);
end;

procedure TAmyChromiumWebContainer.DoChromiumBeforeUnloadDialog(Sender: TObject; const browser: ICefBrowser;
  const messageText: ustring; isReload: Boolean; const callback: ICefJsDialogCallback; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumBeforeUnloadDialog');
end;

procedure TAmyChromiumWebContainer.DoChromiumCancelGeolocationPermission(Sender: TObject; const browser: ICefBrowser;
  const requestingUrl: ustring; requestId: Integer);
begin
  Logger.Debug('Chromium.DoChromiumCancelGeolocationPermission');
end;

procedure TAmyChromiumWebContainer.DoChromiumCertificateError(Sender: TObject; const browser: ICefBrowser;
  certError: Integer; const requestUrl: ustring; const sslInfo: ICefSslInfo; const callback: ICefRequestCallback;
  out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumCertificateError');
end;

procedure TAmyChromiumWebContainer.DoChromiumClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumClose');
end;

procedure TAmyChromiumWebContainer.DoChromiumConsoleMessage(Sender: TObject; const browser: ICefBrowser; const message,
  source: ustring; line: Integer; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumConsoleMessage: ' + source);
end;

procedure TAmyChromiumWebContainer.DoChromiumContextMenuCommand(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags;
  out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumContextMenuCommand');
end;

procedure TAmyChromiumWebContainer.DoChromiumContextMenuDismissed(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame);
begin
  Logger.Debug('Chromium.DoChromiumContextMenuDismissed');
end;

procedure TAmyChromiumWebContainer.DoChromiumDialogClosed(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug('Chromium.DoChromiumDialogClosed');
end;

procedure TAmyChromiumWebContainer.DoChromiumDownloadUpdated(Sender: TObject; const browser: ICefBrowser;
  const downloadItem: ICefDownloadItem; const callback: ICefDownloadItemCallback);
begin
  Logger.Debug('Chromium.DoChromiumDownloadUpdated');
end;

procedure TAmyChromiumWebContainer.DoChromiumDragEnter(Sender: TObject; const browser: ICefBrowser;
  const dragData: ICefDragData; mask: TCefDragOperations; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumDragEnter');
end;

procedure TAmyChromiumWebContainer.DoChromiumDraggableRegionsChanged(Sender: TObject; const browser: ICefBrowser;
  regionsCount: NativeUInt; regions: PCefDraggableRegionArray);
begin
  Logger.Debug('Chromium.DoChromiumDraggableRegionsChanged');
end;

procedure TAmyChromiumWebContainer.DoChromiumFavIconUrlChange(Sender: TObject; const browser: ICefBrowser;
  const iconUrls: TStrings);
begin
  Logger.Debug('Chromium.DoChromiumFavIconUrlChange: ' + iconUrls.Text);
end;

procedure TAmyChromiumWebContainer.DoChromiumFileDialog(Sender: TObject; const browser: ICefBrowser;
  mode: TCefFileDialogMode; const title, defaultFilePath: ustring; acceptFilters: TStrings;
  selectedAcceptFilter: Integer; const callback: ICefFileDialogCallback; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumFileDialog');
end;

procedure TAmyChromiumWebContainer.DoChromiumFindResult(Sender: TObject; const browser: ICefBrowser; identifier,
  count: Integer; const selectionRect: PCefRect; activeMatchOrdinal: Integer; finalUpdate: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumFindResult');
end;

procedure TAmyChromiumWebContainer.DoChromiumFullScreenModeChange(Sender: TObject; const browser: ICefBrowser;
  fullscreen: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumFullScreenModeChange');
end;

procedure TAmyChromiumWebContainer.DoChromiumGetAuthCredentials(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring;
  const callback: ICefAuthCallback; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumGetAuthCredentials');
end;

procedure TAmyChromiumWebContainer.DoChromiumGetResourceHandler(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest; out Result: ICefResourceHandler);
begin
  Logger.Debug('Chromium.DoChromiumGetResourceHandler: ' + request.Url);
end;

procedure TAmyChromiumWebContainer.DoChromiumGotFocus(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug('Chromium.DoChromiumGotFocus');
end;

procedure TAmyChromiumWebContainer.DoChromiumJsdialog(Sender: TObject; const browser: ICefBrowser; const originUrl,
  acceptLang: ustring; dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring;
  callback: ICefJsDialogCallback; out suppressMessage, Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumJsdialog');
end;

procedure TAmyChromiumWebContainer.DoChromiumKeyEvent(Sender: TObject; const browser: ICefBrowser;
  const event: PCefKeyEvent; osEvent: PMsg; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumKeyEvent');
end;

procedure TAmyChromiumWebContainer.DoChromiumLoadEnd(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; httpStatusCode: Integer);
begin
  Logger.Debug('Chromium.DoChromiumLoadEnd');

  FWebBrowser.Browser.SendProcessMessage(PID_RENDERER,
    TCefProcessMessageRef.New('visitdom'));
end;

procedure TAmyChromiumWebContainer.DoChromiumLoadError(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring);
begin
  Logger.Debug('Chromium.DoChromiumLoadError');
end;

procedure TAmyChromiumWebContainer.DoChromiumLoadingStateChange(Sender: TObject; const browser: ICefBrowser; isLoading,
  canGoBack, canGoForward: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumLoadingStateChange');
end;

procedure TAmyChromiumWebContainer.DoChromiumLoadStart(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame);
begin
  Logger.Debug('Chromium.DoChromiumLoadStart');
end;

procedure TAmyChromiumWebContainer.DoChromiumOpenUrlFromTab(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
  out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumOpenUrlFromTab');
end;

procedure TAmyChromiumWebContainer.DoChromiumPluginCrashed(Sender: TObject; const browser: ICefBrowser;
  const pluginPath: ustring);
begin
  Logger.Debug('Chromium.DoChromiumPluginCrashed');
end;

procedure TAmyChromiumWebContainer.DoChromiumPreKeyEvent(Sender: TObject; const browser: ICefBrowser;
  const event: PCefKeyEvent; osEvent: PMsg; out isKeyboardShortcut, Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumPreKeyEvent');
end;

procedure TAmyChromiumWebContainer.DoChromiumProcessMessageReceived(Sender: TObject; const browser: ICefBrowser;
  sourceProcess: TCefProcessId; const message: ICefProcessMessage; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoProcessMessageReceived');
end;

procedure TAmyChromiumWebContainer.DoChromiumProtocolExecution(Sender: TObject; const browser: ICefBrowser;
  const url: ustring; out allowOsExecution: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumProtocolExecution');
end;

procedure TAmyChromiumWebContainer.DoChromiumQuotaRequest(Sender: TObject; const browser: ICefBrowser;
  const originUrl: ustring; newSize: Int64; const callback: ICefRequestCallback; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumQuotaRequest');
end;

procedure TAmyChromiumWebContainer.DoChromiumRenderProcessTerminated(Sender: TObject; const browser: ICefBrowser;
  status: TCefTerminationStatus);
begin
  Logger.Debug('Chromium.DoChromiumRenderProcessTerminated');
end;

procedure TAmyChromiumWebContainer.DoChromiumRenderViewReady(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug('Chromium.DoChromiumRenderViewReady');
end;

procedure TAmyChromiumWebContainer.DoChromiumRequestGeolocationPermission(Sender: TObject; const browser: ICefBrowser;
  const requestingUrl: ustring; requestId: Integer; const callback: ICefGeolocationCallback; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumRequestGeolocationPermission');
end;

procedure TAmyChromiumWebContainer.DoChromiumResetDialogState(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug('Chromium.DoChromiumResetDialogState');
end;

procedure TAmyChromiumWebContainer.DoChromiumResourceRedirect(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest; var newUrl: ustring);
begin
  Logger.Debug('Chromium.DoChromiumResourceRedirect: ' + request.Url);
end;

procedure TAmyChromiumWebContainer.DoChromiumResourceResponse(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumResourceResponse: ' + request.Url);
end;

procedure TAmyChromiumWebContainer.DoChromiumRunModal(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumRunModal');
end;

procedure TAmyChromiumWebContainer.DoChromiumSetFocus(Sender: TObject; const browser: ICefBrowser;
  source: TCefFocusSource; out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumSetFocus');
end;

procedure TAmyChromiumWebContainer.DoChromiumStatusMessage(Sender: TObject; const browser: ICefBrowser;
  const value: ustring);
begin
  Logger.Debug('Chromium.DoChromiumStatusMessage: ' + value);
end;

procedure TAmyChromiumWebContainer.DoChromiumTakeFocus(Sender: TObject; const browser: ICefBrowser; next: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumTakeFocus');
end;

procedure TAmyChromiumWebContainer.DoChromiumTitleChange(Sender: TObject; const browser: ICefBrowser;
  const title: ustring);
begin
  Logger.Debug('Chromium.DoChromiumTitleChange: ' + title);
end;

procedure TAmyChromiumWebContainer.DoChromiumTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring;
  out Result: Boolean);
begin
  Logger.Debug('Chromium.DoChromiumTooltip');
end;

{$ENDREGION}

function TAmyChromiumWebContainer.GetAmyChromium: IAmyChromium;
begin
  Result := FAmyChromium;
end;

function TAmyChromiumWebContainer.GetDebugger: Boolean;
begin
  Result := FDebugger;
end;

function TAmyChromiumWebContainer.GetURL: string;
begin
  Result := FURL;
end;

procedure TAmyChromiumWebContainer.SetDebugger(const Value: Boolean);
begin
  if Value then
    FWebBrowser.ShowDevTools(nil)
  else
    FWebBrowser.CloseDevTools;

  FDebugger := Value;
end;

procedure TAmyChromiumWebContainer.SetURL(const URL: string);
begin
  FWebBrowser.Load(URL);
end;


initialization
  TLogPropertyConfigurator.Configure('log4d.properties');

  Logger := DefaultHierarchy.GetLogger('webkit');

finalization


end.
